<?php

namespace app\model\exam;

use app\model\BaseModel;
use app\model\office\OfficeClass;
use think\model\concern\SoftDelete;

class ExamSend extends BaseModel
{
    use SoftDelete;

    /**
     * 数据表主键
     * @var string
     */
    protected $pk = 'id';

    /**
     * 模型名称
     * @var string
     */
    protected $table = 'free_exam_send';
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = '0000-00-00 00:00:00';

    protected $type = [
        'video_monitor' => 'boolean',
        'exam_model' => 'boolean',
        'chop_screen' => 'boolean',
        'exam_late' => 'boolean',
        'exam_shor' => 'boolean',
        'face' => 'boolean',
        'status' => 'boolean',
        'exam_tian' => 'boolean',
    ];

    public function OfficeClass()
    {
        return $this->hasOne(OfficeClass::class, 'id', 'class_id');
    }

    public function paper()
    {
        return $this->hasOne(ExamPaper::class, 'id', 'paper_id');
    }

    public function getPatternAttr($value)
    {
        $status = [1 => '考试', 0 => '作业'];
        return $status[$value];
    }

    public function setPatternAttr($value)
    {
        $status = ['考试' => 1, '作业' => 0];
        return $status[$value];
    }

    public function setFaceAttr($value)
    {
        $status = [true => 1, false => 0];
        return $status[$value];
    }

    public function searchPatternAttr($query, $value)
    {
        if (isset($value)) $query->where('pattern', 'like', '%' . $value . '%');
    }

    public function searchTitleAttr($query, $value)
    {
        $query->where('title', 'like', '%' . $value . '%');
    }
}